package com.example.esdemo.configure;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ReturnedMessage;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

/**
 * rabbitmq 发送者确认回调
 *
 * @author Cary
 * @date 2022/6/23
 */
@Slf4j
@Component
public class RabbitCallbackConfig implements RabbitTemplate.ConfirmCallback, RabbitTemplate.ReturnsCallback {
    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        if (!ack) {
            log.error("[Rabbitmq]消息发送异常：correlationData={} , cause={}", correlationData, cause);
        }
    }

    @Override
    public void returnedMessage(ReturnedMessage returnedMessage) {
        log.error("[Rabbitmq]消息未进入队列：{}", returnedMessage);
    }
}
